package dome1;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

class Book {}
class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        if(nums1==null) {
            return;
        }
        if(nums2==null) {
            return;
        }
        m--;
        n--;
        while(n>=0&&m>=0) {
            if(nums1[m]>=nums2[n]) {
                nums1[m+n+1]=nums1[m];
                m--;
            }else {
                nums1[m+n+1]=nums2[n];
                n--;
            }
        }
        if(n>=0) {
            while(n>=0) {
                nums1[m+n+1]=nums2[n];
                n--;
            }
        }
    }
}
class Solution1 {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> lists = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < i; j++) {
                if(i == 0||j == i) {
                    list.add(1);
                }else {
                    list.add(lists.get(i-1).get(j) + lists.get(i-1).get(j-1));
                }
            }
            lists.add(list);
        }
        return lists;
    }
}
public class Text {
    public static void main(String[] args) {

    }

    public static void main7(String[] args) {
//        List<List<Integer>>
    }
    public static void main6(String[] args) {
        int[] num1 =new int[]{1,2,3,0,0,0};
        int[] num2 = {2,4,6};
        Solution solution = new Solution();
        solution.merge(num1,3,num2,3);

    }
    public static void main5(String[] args) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        System.out.println("======直接输出======");
        System.out.println(list);
        System.out.println("======for循环======");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        System.out.println("======for each======");
        for (Integer x : list) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("======迭代器遍历1======");
        Iterator list1 = list.iterator();
        while(list1.hasNext()) {
            System.out.print(list1.next() + " ");
        }
        System.out.println();
        System.out.println("======迭代器遍历2======");
        ListIterator list2 = list.listIterator();
        while(list2.hasNext()) {
            System.out.print(list2.next() + " ");
        }
        System.out.println();
        System.out.println("======迭代器遍历3======");//从后往前
        ListIterator listPrev = list.listIterator(list.size());
        while(listPrev.hasPrevious()) {
            System.out.print(listPrev.previous() + " ");
        }
        System.out.println();
    }
    public static void main4(String[] args) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        List<Integer> listTmp = list.subList(1,3);//截取[1,3)的值,返回的是[1,3)的地址
        System.out.println(listTmp);
        System.out.println("==============");
        listTmp.set(0,99);
        System.out.println("listTmp:" + listTmp);
        System.out.println("list:" + list);
    }
    public static void main3(String[] args) {
        ArrayList<Integer> list1 = new ArrayList<Integer>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        list1.add(4);
        list1.remove(1);
        System.out.println("list1:" + list1);

        ArrayList<Integer> list2 = new ArrayList<Integer>();
        list2.add(1);
        list2.add(2);
        list2.add(3);
        list2.add(4);
//        list2.remove(new Integer(1));//老版本
        System.out.println("list2:" + list2);
    }
    public static void main2(String[] args) {
        ArrayList<Integer> list1 = new ArrayList<Integer>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        list1.add(4);

        ArrayList<Integer> list2 = new ArrayList<Integer>();
        list2.add(11);
        list2.add(22);
        list2.add(33);
        list2.add(44);

        //list2中的泛型要是list1泛型的子类
        list1.addAll(list2);
        System.out.println(list1);
    }
    public static void main1(String[] args) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(0);
        list.add(1);
        list.add(2);
        list.add(3);

        ArrayList<Book> booklist = new ArrayList<Book>();//书架
    }
}
